<!DOCTYPE html>
<html lang="en">
<head>
    <title>费用报销列表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <script src="https://file.ggxqce.com/web/vue.min.js"></script>

    <style>
        [v-cloak] {
            display: none;
        }

        * {
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            font-size: 12px;
        }

        body {
            margin: 1px;
            background: #f8f8f8;
        }

        table {
            border-spacing: 0;
            border-collapse: collapse;
            display: table;
        }

        table.text-center, table.text-center td, table.text-center th {
            text-align: center;
            font-size: 12px;
        }

        .table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td {
            border: 1px solid #cbcbcd;
            font-weight: normal;
            height: 24px;
        }

        .table th {
            background: yellow;
        }

        .table-bordered {
            border: 1px solid #cbcbcd;
        }

        .table {
            width: 100%;
            max-width: 100%;
        }

        .hidden {
            display: none;
        }

        .lineOne {
            text-align: left;
        }

        .lineOne span {
            max-height: 24px;
            line-height: 24px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: left;
        }

        .mScrollBox {
            float: left;
            position: relative;
            overflow: hidden;
        }

        .infoReport {
            text-align: center;
            margin: 0;
            margin-bottom: 10px;
        }

        .moduleName {
            height: 20px;
            line-height: 20px;
            background: #f8f8f8;
            font-weight: bold;
            font-size: 14px;
        }

        .oaReportNav {
            position: relative;
        }

        .toggleDiv {
            height: 20px;
            line-height: 20px;
            margin-bottom: 10px;
        }

        .toggleDiv div {
            width: 50%;
            float: left;
            text-align: center;
        }

        .toggleDiv div.active {
            border-bottom: 2px solid #2289ee;
        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }
    </style>
</head>
<body>
<section class="content" id="app" v-cloak>
    <div class="div-td-content-more"><i></i></div>
    <div style="padding:10px 0;background: #fff;overflow: hidden;" id="costDepart">
        <!--<div class="infoReport">-->
        <!--<span>金额(总)：{{cost.all.money?fmoney(cost.all.money):"0"}}</span>-->
        <!--<span>已报销(总)：{{cost.all.bxMoney?fmoney(cost.all.bxMoney):"0"}}</span><br>-->
        <!--<span>未报销(总)：{{cost.all.unBxMoney?fmoney(cost.all.unBxMoney):"0"}}</span>-->
        <!--</div>-->
        <div class="mScrollBox" style="width:100%;">
            <template v-if="frontFlag==1">
                <table class="table table-bordered text-center table-width">
                    <thead>
                    <tr>
                        <!--<th style="width: 5%">序号</th>-->
                        <th style="width: 10%">时间</th>
                        <!--<th style="width: 14%">姓名</th>-->
                        <th style="width: 18%">费用名称</th>
                        <th style="width: 14%">金额(元)</th>
                        <th style="width: 13%">是否有<br>发票</th>
                        <th style="width: 16%">报销状态</th>
                        <th style="width: 16%">说明</th>
                    </tr>
                    </thead>
                    <tbody>
                    <template v-if="cost.list.length>0">
                        <tr v-for="(item,i) in cost.list">
                            <!--<td>{{i+1}}</td>-->
                            <template v-if="item.money!=0">
                                <td>{{(item.reportDate).substr(5,10)}}</td>
                                <!--<td>{{item.userName}}</td>-->
                                <td @click="lookCostView(item)" v-if="item.auditFlag!=''"
                                    style="text-align:center;color:#169BD5;cursor: pointer">
                                    {{item.costSmallName}}
                                </td>
                                <td v-else>{{item.costSmallName}}</td>
                                <td>
                                    {{item.money}}
                                </td>
                                <td>
                                    {{item.invoiceFlag=="1"?"有":"无"}}
                                </td>
                                <td>
                                    {{item.bxState=="1"?"已报销":item.bxState=="-1"?"已作废":"未报销"}}
                                </td>
                                <td class="lineOne">
                                    <span>{{item.remark}}</span>
                                </td>
                            </template>
                        </tr>
                        <tr>
                            <td>合计</td>
                            <td>-</td>
                            <td>{{cost.all.money?fmoney(cost.all.money):"0"}}</td>
                            <td>-</td>
                            <td>-</td>
                            <td>-</td>
                        </tr>
                    </template>

                    <template v-else>
                        <tr>
                            <td colspan="7">暂无数据~</td>
                        </tr>
                    </template>
                    </tbody>
                </table>
            </template>
            <template v-else>
                <table class="table table-hover table-bordered text-center">
                    <thead>
                    <tr>
                        <th style="width: 20%;">岗位</th>
                        <th style="width: 12%;">姓名</th>
                        <th style="width: 12%;">金额</th>
                        <th style="width: 12%;">已报销</th>
                        <th style="width: 12%;">未报销</th>
                        <th style="width: 24%;">区域</th>
                    </tr>
                    </thead>
                    <tbody>
                    <template v-if="cost.list.length>0">
                        <tr v-for="(item,i) in cost.list">
                            <template v-if="item.money!='0'">
                            <td>
                                {{item.roleName}}
                            </td>
                            <td>{{item.userName}}</td>
                            <template v-if="item.money=='0'">
                                <td>
                                    -
                                </td>
                            </template>
                            <template v-else>
                                <td @click="openCostPersonal(item,cost.time)"
                                    style="color:#2a8cec;cursor: pointer;">
                                    {{item.money}}
                                </td>
                            </template>
                            <template v-if="item.bxMoney=='0'">
                                <td>
                                    -
                                </td>
                            </template>
                            <template v-else>
                                <td @click="openCostPersonal(item,cost.time,1)"
                                    style="color:#2a8cec;cursor: pointer;">
                                    {{item.bxMoney}}
                                </td>
                            </template>
                            <template v-if="item.unBxMoney=='0'">
                                <td> -
                                </td>
                            </template>
                            <template v-else>
                                <td @click="openCostPersonal(item,cost.time,0)"
                                    style="color:#2a8cec;cursor: pointer;">
                                    {{item.unBxMoney}}
                                </td>
                            </template>
                            <td class="lineOne">
                                <span>{{item.regionName}}</span>
                            </td>
                            </template>
                        </tr>
                        <tr>
                            <td>合计</td>
                            <td>-</td>
                            <td>{{cost.all.money?fmoney(cost.all.money):"0"}}</td>
                            <td>{{cost.all.bxMoney?fmoney(cost.all.bxMoney):"0"}}</td>
                            <td>{{cost.all.unBxMoney?fmoney(cost.all.unBxMoney):"0"}}</td>
                            <td>-</td>
                        </tr>
                    </template>

                    <template v-else>
                        <tr>
                            <td colspan="6">暂无数据~</td>
                        </tr>
                    </template>
                    </tbody>
                </table>
            </template>
        </div>
    </div>

    <!-- /.box-body -->
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="/dist/plugins/scroll/myScroll.js"></script>
<!--框架已定义 JS-->
<!--oa自定义  JS-->
<script src="/dist/js/oaApp.js"></script>

<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script>
    $(function () {
        $("body").on("click", ".lineOne", function (e) {
            if ($(".div-td-content-more").is(":hidden")) {
                var text = $(this).text();
                if (text != "") {
                    text = "<i></i>" + text;
                    $(".div-td-content-more").html(text).css({
                        "width": $(this).outerWidth() + "px",
                        "left": $(this).offset().left,
                        "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                    }).show();
                    e.stopPropagation();
                }
            } else {
                $(".div-td-content-more").hide();
            }
        });
        $("body").on("click", ".div-td-content-more", function (e) {
            e.stopPropagation();
        });
        $("body").on("click", function () {
            $(".div-td-content-more").hide();
        });
    });
</script>
<script>
    $.ajaxSetup({
        global: true,
        type: "POST",
        cache: false,
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        beforeSend: function () {
        },
        complete: function () {

        },
        error: function (e) {
            alert('error' + e.responseText);
        }
    });
    $.extend($.wyui, {
        postMethod: function (url, data, callback, sync, id) {
            if (!id) {
                id = "#app"
            }
            $.ajax({
                url: server.ip + url,
                async: sync ? false : true,
                data: JSON.stringify(data),
                beforeSend: function () {

                },
                complete: function () {
                    setTimeout(function () {
                    }, 1000);

                },
                success: function (r) {
                    if (!r.e.code) {
                        callback(r.data.sendData);
                    } else {
                        alert(r.e.desc);
                    }
                },
                error: function (e) {
                    alert(url + e.responseText);
                }
            });
        },
    });
</script>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            departId: getUrlParamObj().departId,
            isClick: getUrlParamObj().isClick?getUrlParamObj().isClick:false,
            frontFlag: getUrlParamObj().frontFlag,
            yesterday: new Date(new Date() - 24 * 60 * 60 * 1000).Format("yyyy-MM-dd"),
            today: new Date().Format("yyyy-MM-dd"),//今天
            hour: new Date().getHours(),
            thisMonth: new Date().Format("yyyy-MM"),
            thisWeek: new Date().Format("yyyy-MM-dd") + "-w",
            tab: [],
            userId:getUrlParamObj().userId,
            cost: {
                time: getUrlParamObj().dateTime,
                list: [],
                all: {"money": "", "bxMoney": "", "unBxMoney": ""}
            }
        },
        methods: {
            fmoney: function (s, n) {
                n = n > 0 && n <= 20 ? n : 2;
                s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
                var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1],
                    t = "";
                for (i = 0; i < l.length; i++) {
                    t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
                }
                return t.split("").reverse().join("") + "." + r;
            },
            //获取tab
            getTab: function () {
                var that = this;
                var dateTime = new Date().Format("yyyyMM");
                for (var i = 0; i < 5; i++) {
                    dateTime = that.getLastEndMonth(dateTime);
                    that.tab.push(that.insert_flg(dateTime, "-", "4"))
                }
                console.log(that.tab)
            },
            getLastEndMonth: function (beginYearMonth) {
                var strYear = parseInt(beginYearMonth.substr(0, 4), 10);
                var strMonth = parseInt(beginYearMonth.substr(4, 6), 10);
                if (strMonth - 1 == 0) {
                    strYear -= 1;
                    strMonth = 12;
                } else {
                    strMonth -= 1;
                }
                if (strMonth < 10) {
                    strMonth = "0" + strMonth;
                }
                var monthstr = strYear + "" + strMonth;
                return monthstr;
            },
            //格式化日期
            insert_flg: function (str, flg, sn) {
                var newstr = "";
                for (var i = 0; i < str.length; i += sn) {
                    var tmp = str.substring(i, i + sn);
                    newstr += tmp + flg;
                }
                newstr = newstr.substr(0, newstr.length - 1);
                var st1 = newstr.substr(2, 2);
                var st2 = newstr.substr(5, 2);
                var newstr3 = st2 + "/" + st1;
                var obj = {str: newstr3, time: newstr};
                return obj;
            },
            //tab中点击日期刷新对应数据
            refreshData: function (dataType, fun, time) {
                var that = this;
                that[dataType].time = time;
                that[fun]();
            },
            isActive: function (item) {
                var that = this;
                if (that.cost.time == item) {
                    return true;
                }
            },
            //获取合计
            getCount: function (arr, key) {
                var number = 0;
                for (var i = arr.length - 1; i >= 0; i--) {
                    number += (arr[i][key] && arr[i][key] != '-' ? arr[i][key] : 0)

                }
                return number;
            },
            //合并单元格
            tablesMergeCell: function (list) {
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            getFrontFlag:function(){
                var that = this;
                //user/getUserViewById.json
                $.wyui.postMethod(urlConfig.system.user.getUserViewById, {
                    "id": that.userId}, function (r) {
                    // var data = trimRN2(data);
                    that.frontFlag = r.frontFlag;
                    that.get_costDepart();
                })
            },
            lookCostView: function (item) {
                var that = this;
                var obj = {
                    type: 'cost',
                    costType: item.costSmallName,
                    id: item.costId
                }
                prompt(JSON.stringify(obj))
            },
            //获取费用报表-区域经理
            get_costDepart: function () {
                var that = this;
                if(that.isClick){
                    $.wyui.postMethod(urlConfig.report.reportCost.getForDepartByDepartIdAndDateTime, {
                        "departId": that.departId,
                        "dateTime": that.cost.time
                    }, function (data) {
//                    var data=trimRN2(data);
                        that.cost.list = that.tablesMergeCell(data);
                        that.cost.all.money = that.getCount(that.cost.list, "money");
                        that.cost.all.bxMoney = that.getCount(that.cost.list, "bxMoney");
                        that.cost.all.unBxMoney = that.getCount(that.cost.list, "unBxMoney");
                        /* console.log(data);
                         if (data.length == 0) {
                         that.get_costDepart2()
                         }*/
                    });
                }else{
                    if(that.frontFlag==1){
                        $.wyui.postMethod(urlConfig.report.reportCost.getForPersonalByUserIdAndDateTime, {
                            "userId": that.userId,
                            "dateTime": that.cost.time,
                            "start":getUrlParamObj().start
                        }, function (data) {
                            var data = trimRN2(data);
                            that.cost.list = that.tablesMergeCell(data);
                            that.cost.all.money=that.getCount(that.cost.list,"money");
                            that.cost.all.bxMoney=that.getCount(that.cost.list,"bxMoney");
                            that.cost.all.unBxMoney=that.getCount(that.cost.list,"unBxMoney");
                            console.log(data);
                        });
                    }else{
                        $.wyui.postMethod(urlConfig.report.reportCost.getForDepartByUserIdAndDateTime, {
                            "userId": getUrlParamObj().userId,
                            "dateTime": that.cost.time
                        }, function (data) {
                            var data = trimRN2(data);
                            that.cost.list = that.tablesMergeCell(data);
                            that.cost.all.money = that.getCount(that.cost.list, "money");
                            that.cost.all.bxMoney = that.getCount(that.cost.list, "bxMoney");
                            that.cost.all.unBxMoney = that.getCount(that.cost.list, "unBxMoney");
                            console.log(data);
                        })
                    };
                }

            },
            /* //获取费用报表-大区经理
             get_costDepart2: function () {
             var that = this;
             alert(that.frontFlag);
             alert(that.frontFlag=='');

             },*/
            //查看费用报销 个人详情页面
            openCostPersonal: function (item, dateTime, start) {
                var startValue = start;
                if (!startValue && startValue != 0) {
                    startValue = ""
                }

                var that = this;
                var obj = {
                    type: 'customerList',
                    url: '/reportForm/cost/costPersonalApp.html?userId=' + item.userId + '&userName=' + item.userName + '&dateTime=' + dateTime + '&start=' + startValue,
                    id: item.userId,
                    name: item.userName,
                    dateTime: dateTime,
                    start: startValue
                }
                prompt(JSON.stringify(obj))
//                top.closeTabByPageId("openCostPersonal");
//                top.addTabs({
//                    id: "openCostPersonal",
//                    title: item.userName+"费用报销详情",
//                    close: true,
//                    url: '/reportForm/cost/costPersonal.html?userId='+item.userId+"&dateTime="+dateTime+"&start="+startValue
//                });
            },

        },
        mounted: function () {
            var that = this;
            //1.获取前5个月的tab数据
            this.getTab();
            this.getFrontFlag();
        }
    });
</script>

</body>
</html>